package com.atguigu.yygh.shop.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.shop.Shop;
import com.atguigu.yygh.shop.service.ShopService;
import com.atguigu.yygh.vo.shop.ShopQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/shop/shop")
//@CrossOrigin
public class ShopController {

    @Autowired
    private ShopService shopService;

    //商铺列表(条件查询分页)
    @GetMapping("list/{page}/{limit}")
    public Result listShop(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           ShopQueryVo shopQueryVo) {
        Page<Shop> pageModel = shopService.selectShopPage(page,limit,shopQueryVo);
        List<Shop> content = pageModel.getContent();
        long totalElements = pageModel.getTotalElements();

        return Result.ok(pageModel);
    }

    //更新商铺上线状态
    @ApiOperation(value = "更新商铺上线状态")
    @GetMapping("updateShopStatus/{id}/{status}")
    public Result updateShopStatus(@PathVariable String id,@PathVariable Integer status) {
        shopService.updateStatus(id,status);
        return Result.ok();
    }

    //商铺详情信息
    @ApiOperation(value = "商铺详情信息")
    @GetMapping("showShopDetail/{id}")
    public Result showShopDetail(@PathVariable String id) {
        Map<String, Object> map = shopService.getShopById(id);
        return Result.ok(map);
    }
}
